package com.th.basemodel.utils

import android.content.Context
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import java.util.concurrent.Executors

class AppUtil {
    companion object {
        var adid: String = ""

        @JvmField
        var sessionId: String = ""

        @JvmField
        var userPhone: String = ""

        @JvmField
        var latitude: Double = 0.0

        @JvmField
        var longitude: Double = 0.0

        fun init(context: Context) {
            setAdid(context)
        }

        private fun setAdid(context: Context) {
            Executors.newCachedThreadPool().execute {
                try {
                    val idInfo: AdvertisingIdClient.Info = AdvertisingIdClient.getAdvertisingIdInfo(
                        context
                    )
                    adid = idInfo.id ?: ""
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
        }

        fun getVersionName(): String {
            var versionName = ""
            try {
                //获取软件版本号，对应AndroidManifest.xml下android:versionName
                versionName = CommUtils.getContext().packageManager
                    .getPackageInfo(CommUtils.getContext().packageName, 0)
                    .versionName
            } catch (e: Exception) {
                e.printStackTrace()
            }
            return versionName
        }
    }
}